﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using Entities;
using WebUI.Models;

namespace WebUI.Controllers
{
    public partial class DetailsController : Controller
    {
        #region Member Variables

        readonly IDetailsService _detailsService;

        #endregion

        #region Constructor

        public DetailsController(IDetailsService detailsService)
        {
            this._detailsService = detailsService;
        }

        #endregion

        #region Action Methods

        [HttpGet]
        public virtual ViewResult FileDetails(string objectName)
        {
            var model = new FilesModel { Title = objectName };
            model.FilesFilter.FileName = objectName;

            model.FilesList = _detailsService.GetAllFileActions(objectName);
            return View(model);
        }

        [HttpPost]
        public virtual PartialViewResult FilterFileDetails(FilterOperations filter)
        {
            var results = _detailsService.SearchFileActions(filter.FileName, filter);
            return PartialView(MVC.Reports.Details.Views._FileDetailsGrid, results);
        }

        [HttpGet]
        public virtual ViewResult UserDetails(string userName)
        {
            UserDetails userDetails = _detailsService.GetAllUserActions(userName);
            userDetails.Filter = new FilterOperations
            {
                User = userName,
                RenderOperationTypes = true,
                RenderFileType = true,
            };
            userDetails.UserName = userName;
            return View(userDetails);
        }

        [HttpPost]
        public virtual PartialViewResult FilterUserDetails(FilterOperations filter)
        {
            UserDetails userDetails = _detailsService.SearchUserActions(filter.User, filter);
            return PartialView(MVC.Reports.Details.Views._UserDetailsGrid, userDetails);
        }

        #endregion
    }
}